home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / c1.zip / ASINE.C < prev    next >
Text File  |  1987-06-18  |  2KB  |  82 lines

  1.  
  2. /***********************************************************
  3.  *               The TULSA IBM C BOARD                     *
  4.  *                   918-664-8737                          *
  5.  *             300/1200 XMODEM, 24 Hours                   *
  6.  **********************************************************/
  7.  
  8. #include "math.h"
  9. #include "errno.h"
  10.  
  11. double arcsine();
  12.  
  13. double asin(x)
  14. double x;
  15. {
  16.         return arcsine(x,0);
  17. }
  18.  
  19. double acos(x)
  20. double x;
  21. {
  22.         return arcsine(x,1);
  23. }
  24.  
  25. #define P1 -0.27368494524164255994e+2
  26. #define P2 +0.57208227877891731407e+2
  27. #define P3 -0.39688862997504877339e+2
  28. #define P4 +0.10152522233806463645e+2
  29. #define P5 -0.69674573447350646411
  30. #define Q0 -0.16421096714498560795e+3
  31. #define Q1 +0.41714430248260412556e+3
  32. #define Q2 -0.38186303361750149284e+3
  33. #define Q3 +0.15095270841030604719e+3
  34. #define Q4 -0.23823859153670238830e+2
  35.  
  36. #define P(g) ((((P5*g P4)*g P3)*g P2)*g P1)
  37. #define Q(g) (((((g Q4)*g Q3)*g Q2)*g Q1)*g Q0)
  38.  
  39. double arcsine(x,flg)
  40. double x;
  41. {
  42.         double y, g, r;
  43.         register int i;
  44.         extern int errno;
  45.         static double a[2] = { 0.0, 0.78539816339744830962 };
  46.         static double b[2] = { 1.57079632679489661923, 0.78539816339744830962 };
  47.  
  48.         y = fabs(x);
  49.         i = flg;
  50.         if (y < 2.3e-10)
  51.                 r = y;
  52.         else {
  53.                 if (y > 0.5) {
  54.                         i = 1-i;
  55.                         if (y > 1.0) {
  56.                                 errno = EDOM;
  57.                                 return 0.0;
  58.                         }
  59.                         g = (0.5-y)+0.5;
  60.                         g = ldexp(g,-1);
  61.                         y = sqrt(g);
  62.                         y = -(y+y);
  63.                 } else
  64.                         g = y*y;
  65.                 r = y + y*
  66.                                 ((P(g)*g)
  67.                                 /Q(g));
  68.         }
  69.         if (flg) {
  70.                 if (x < 0.0)
  71.                         r = (b[i] + r) + b[i];
  72.                 else
  73.                         r = (a[i] - r) + a[i];
  74.         } else {
  75.                 r = (a[i] + r) + a[i];
  76.                 if (x < 0.0)
  77.                         r = -r;
  78.         }
  79.         return r;
  80. }
  81.  
  82.